﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IConfig</summary>
	public class IConfig : IDisposable
	{
        protected IParamList FParams; // Zoznam parametrov

        /// <summary>Konstruktor</summary>
        public IConfig()
        {
            FParams = new IParamList(); // Vytvorim objekt
        }
        /// <summary>Dispose metoda</summary>
        public void Dispose()
        {
            FParams = (IParamList)ICore.DisposeObject(FParams); // Volam dispose
        }

        /// <summary>Ulozenie konfiguracie do suboru</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>true / false</returns>
        public bool SaveConfiguration(string pFileName)
        {
            string Data = FParams.Serialize(false); // Serializujem obsah
            return IFileSystem.SaveStringToTextFile(pFileName, Data, true) == 0; // Ulozim do suboru
        }
        /// <summary>Nacitanie konfiguracie</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <returns>true / false</returns>
        public bool LoadConfiguration(string pFileName)
        {
            string Data;
            if (IFileSystem.LoadStringFromTextFile(pFileName, out Data) != 0) return false; // Nacitam obsah suboru
            FParams.Deserialize(Data, false); // Deserializujem obsah
            return true; // Vsetko OK
        }

        /// <summary>Test ci parameter existuje</summary>
        /// <param name="pName">nazov</param>
        /// <returns>true / false</returns>
        public bool Exists(string pName)
        {
            return FParams.Exists(pName); 
        }
        /// <summary>Vymazanie parametra</summary>
        /// <param name="pName">nazov</param>
        public void Delete(string pName)
        {
            FParams.Delete(pName); // Volam vymazanie
        }

        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, string pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, int pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, uint pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, long pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, ulong pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, double pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }
        /// <summary>Ulozenie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pValue">hodnota</param>
        public void SetParam(string pName, bool pValue)
        {
            FParams.SetParam(pName, pValue); // Volam ulozenie
        }

        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public string GetParam(string pName, string pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public int GetParam(string pName, int pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public uint GetParam(string pName, uint pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public long GetParam(string pName, long pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public ulong GetParam(string pName, ulong pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public double GetParam(string pName, double pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
        /// <summary>Ziskanie hodnoty parametra</summary>
        /// <param name="pName">nazov</param>
        /// <param name="pDefValue">prednastavena hodnota</param>
        /// <returns>aktualna alebo prednastavena hodnota</returns>
        public bool GetParam(string pName, bool pDefValue)
        {
            return FParams.GetParam(pName, pDefValue); // Volam ziskanie parametra
        }
    }
}
